package http;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class MyHttpServer {

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8001);
        for (; ; ) {
            Socket socket = serverSocket.accept();
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(
                            new DataInputStream(socket.getInputStream())));
            String line = "";
            while ((line = reader.readLine()) != null && line.length() > 0) {
                System.out.println(line);
            }
            BufferedWriter writer = new BufferedWriter(
                    new OutputStreamWriter(
                            new DataOutputStream(socket.getOutputStream())));
            writer.write("HTTP/1.1 200 ok\n\nHello World!\n");
            writer.flush();
            socket.close();
        }
    }
}
